package com.sbxBase.controller;


import com.sbxBase.entity.LoginUser;
import com.common.entity.sbxBase.User;
import com.sbxBase.service.UserService;
import com.common.entity.Result;
import com.common.validations.RequiredField;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "匿名用户")
@RestController
@RequestMapping("/anonymousUser")
public class AnonymousUserController {
    @Resource
    private UserService userService;


    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Result userLogin(@RequestBody LoginUser loginUser, HttpServletResponse response) {
        User user = userService.userLogin(loginUser, response);
        return Result.success(user);
    }

    @PostMapping("/register")
    @ApiOperation("用户注册")
    public Result register(@RequestBody @Validated(value = RequiredField.class) User user) {
        return Result.success( userService.registerByEmail(user));
    }

    @GetMapping("/{email}/confirmEmail/{code}")
    @ApiOperation("校验邮箱")
    public Result confirmEmail(@PathVariable @ApiParam("用户邮箱") String email, @PathVariable @ApiParam("验证码") String code) {
        String info = userService.confirmEmail(email, code);
        return Result.success(info);
    }


}
